package com.bobby.dao.impl;

import com.bobby.dao.BaseDao;
import com.bobby.dao.UserDao;
import com.bobby.pojo.User;

import java.sql.SQLException;

/**
 * @Description TODO
 * @Date 2020/8/13 10:26
 * @Created wenjunpei
 */
public class UserDaoImpl extends BaseDao<User> implements UserDao {
    @Override
    public User queryUserByUsername(String username) throws SQLException {
        String sql = "select * from t_user where username = ?";
        return queryForOne(sql, username);
    }

    @Override
    public User queryUserByUsernameAndPassword(String username , String password) throws SQLException {
        String sql = " select * from t_user where username = ? and password = ?";
        return queryForOne(sql,username,password);
    }

    @Override
    public int saveUser(User user) throws SQLException {
        String sql = "insert into t_user(username,password,email) values(?,?,?)";
        return update(sql,user.getUsername(),user.getPassword(),user.getEmail());
    }
}
